window.addEventListener('load', function () {
    // 自定义配置
    // --------------------------------------------------
    var u_speed = '3500';//轮播图速度   例如  '1000'
    var u_width = '100%';
    var u_height = '100%';
    // --------------------------------------------------
    // 自定义配置
    var lunbo_LY = document.querySelector(".lunbo_LY");
    lunbo_LY.style.width = u_width;
    lunbo_LY.style.height = u_height;
    var ul_LY = lunbo_LY.querySelector('ul');
    var lunbo_LYWidth = lunbo_LY.offsetWidth;
    //index
    var index_LY = null;
    //count_LY
    var count_LY = 0;
    //flag_LY节流阀
    var flag_LY = true;
    //动态生成小圆点
    var circle_LY = lunbo_LY.querySelector('.circle');
    //有几张轮播图就创建几个小圆点
    for (var i = 0; i < ul_LY.children.length; i++) {
        var li_LY = document.createElement('li');
        //设置之定义属性索引号
        li_LY.setAttribute('index_LY', i);
        circle_LY.appendChild(li_LY);
        circle_LY.children[0].className = 'style_white';
        circle_LY.children[i].addEventListener('click', function () {
            //排他法清除其他的小白点
            for (var i = 0; i < circle_LY.children.length; i++) {
                circle_LY.children[i].className = '';
            }
            this.className = 'style_white';
            //得到索引号
            index_LY = this.getAttribute("index_LY");
            count_LY = index_LY;
            //动画
            animate(ul_LY, -index_LY * lunbo_LYWidth);
        })
    }
    lunbo_LY.querySelector("li").className = 'style_white';
    //克隆一份第一个图片到最后
    var frist = ul_LY.children[0].cloneNode(true);
    ul_LY.appendChild(frist);
    // img 加宽高
    var img_LY = lunbo_LY.querySelectorAll("img");
    for (var i = 0; i < img_LY.length; i++) {
        img_LY[i].style.width = lunbo_LY.offsetWidth + 'px';
        img_LY[i].style.height = lunbo_LY.offsetWidth + 'px';
    }
    //////////////////////////////
    circle_LY.children[1].className = 'style_white';
    //右按钮添加点击事件
    var btnRight = lunbo_LY.querySelector('.btn_right');
    btnRight.addEventListener('click', function () {
        if (flag_LY) {
            flag_LY = false;
            if (count_LY == ul_LY.children.length - 1) {
                ul_LY.style.left = 0;
                count_LY = 0;
            }
            count_LY++;
            animate(ul_LY, -count_LY * lunbo_LYWidth, function () {
                flag_LY = true;
            });
            //排他法清除其他的小白点
            for (var i = 0; i < circle_LY.children.length; i++) {
                circle_LY.children[i].className = '';
            }
            if (count_LY == ul_LY.children.length - 1) {
                circle_LY.children[1].className = 'style_white';
            } else {
                //小白点
                circle_LY.children[count_LY + 1].className = 'style_white';
            }
        }

    })
    //左按钮添加点击事件
    var btnLeft = lunbo_LY.querySelector('.btn_left');
    btnLeft.addEventListener('click', function () {
        if (flag_LY) {
            flag_LY = false;
            if (count_LY == 0) {
                count_LY = ul_LY.children.length - 1;
                ul_LY.style.left = -count_LY * lunbo_LYWidth + 'px';
            }
            count_LY--;
            animate(ul_LY, -count_LY * lunbo_LYWidth, function () {
                flag_LY = true;
            });
            // 排他法清除其他的小白点
            for (var i = 0; i < circle_LY.children.length; i++) {
                circle_LY.children[i].className = '';
            }
            if (count_LY == ul_LY.children.length - 1) {
                circle_LY.children[1].className = 'style_white';
            } else {
                //小白点
                circle_LY.children[count_LY + 1].className = 'style_white';
            }
        }
    })
    //自动轮播
    var timer_LY = setInterval(function () {
        btnRight.click();
    }, parseInt(u_speed))//三秒轮播一次
    //鼠标悬停不轮播
    lunbo_LY.addEventListener('mouseenter', function () {
        btnRight.style.display = 'block';
        btnLeft.style.display = 'block';
        clearInterval(timer_LY);
    });
    lunbo_LY.addEventListener('mouseleave', function () {
        btnRight.style.display = 'none';
        btnLeft.style.display = 'none';
        timer_LY = setInterval(function () {
            btnRight.click();
        }, parseInt(u_speed))//三秒轮播一次
    });
})